﻿Imports System.Windows.Forms

Namespace Dialogs

#Region "--Global Enums--"
    ''' <summary>
    ''' Used to determine what type of business rules to apply.
    ''' </summary>
    Public Enum EventMethods
        dbiSchedule_BeforeTimeBarSize = 0
        dbiSchedule_BeforeTimeBarMove = 1
        dbiSchedule_BeforeTimeBarRemove = 2
        dbiSchedule_AfterTimeBarInserted = 3
        ObjectMenu_WarehouseDelete = 4
        ObjectMenu_LoadingDockTransferToWarehouse = 5
        ObjectMenu_LoadingDockDelete = 6
        ObjectMenu_LoadingDockCargoTypeChange = 7
        ObjectMenu_ShipmentTransferToLoadingDock = 8
        ObjectMenu_ShipmentDelete = 9
        ObjectMenu_OrderHeaderDelete = 10
        ObjectMenu_OrderDetailCargoTypeChange = 11
        ObjectMenu_OrderDetailDelete = 12
        ObjectMenu_LoadingDockExceptionRemoveLoadingDock = 13
        ObjectMenu_LoadingDockExceptionAddLoadingDock = 14
        ObjectMenu_RecurrenceLoadingDockExceptionRemoveLoadingDock = 15
        ObjectMenu_RecurrenceLoadingDockExceptionAddLoadingDock = 16
        DbiDayView1_BeforeAppointmentChange = 17
        DbiDayView1_AfterAppointmentAdd = 18

    End Enum
#End Region

    Public Class dlgBusinessRule
        'Inherits from the dlgDefault in the dlgBusinessRule.Designer.vb

#Region "**Local variables**"
        Private l_BRResponse As New dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects.BusinessRuleResponse
        Private l_Allow As Boolean
        Private l_BusinessRulesToApply As dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects
        Private l_CallingControl As Windows.Forms.Control
        Private l_EventArgs As Object
        Private l_EventName As EventMethods
#End Region

#Region "**Public Properties**"
        ''' <summary>
        ''' The business rule response returned from the business rules.
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Business Rules"), _
        System.ComponentModel.Description("The business rule response returned from the business rules.")> _
        Public Property BRResponse() As dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects.BusinessRuleResponse
            Get
                Return l_BRResponse
            End Get
            Set(ByVal value As dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects.BusinessRuleResponse)
                l_BRResponse = value
            End Set
        End Property

        ''' <summary>
        ''' A boolean to indicate wether the changes should be processed.
        ''' </summary>
        <System.ComponentModel.Category("dbiWSF Business Rules"), _
        System.ComponentModel.Description("A boolean to indicate wether the changes should be processed.")> _
        Public Property Allow() As Boolean
            Get
                Return l_Allow
            End Get
            Set(ByVal value As Boolean)
                l_Allow = value
            End Set
        End Property
#End Region

#Region "**Dialog Methods**"
        ''' <summary>Instantiates a new business rules dialog passing a MainBusinessRules object.</summary>
        Public Sub New(ByRef MainBusinessRules As dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects)
            InitializeComponent()
            Me.l_BusinessRulesToApply = MainBusinessRules
        End Sub

        ''' <summary>Starts the business rules process and calls the appropriate "Event Method"</summary>
        ''' <remarks>This method runs Asynchronously to the calling thread.</remarks>
        Public Sub StartProcess(ByVal CallingEventArgs As Object, ByVal CallingEventName As EventMethods, ByVal CallingControl As Windows.Forms.Control)
            Me.dbiListBusinessRules.Items.Clear()
            Me.l_EventArgs = CallingEventArgs
            Me.l_EventName = CallingEventName
            Me.l_CallingControl = CallingControl

            Select Case l_EventName
                Case EventMethods.dbiSchedule_AfterTimeBarInserted
                    Me.dbiSchedule_AfterTimeBarInsert()
                Case EventMethods.dbiSchedule_BeforeTimeBarSize
                    Me.dbiSchedule_BeforeTimeBarSize()
                Case EventMethods.dbiSchedule_BeforeTimeBarMove
                    Me.dbiSchedule_BeforeTimeBarMove()
                Case EventMethods.dbiSchedule_BeforeTimeBarRemove
                    Me.dbiSchedule_BeforeTimeBarRemove()
                Case EventMethods.ObjectMenu_WarehouseDelete
                    ObjectMenu_WarehouseDelete()
                Case EventMethods.ObjectMenu_LoadingDockTransferToWarehouse
                    ObjectMenu_LoadingDockTransferToWarehouse()
                Case EventMethods.ObjectMenu_LoadingDockDelete
                    ObjectMenu_LoadingDockDelete()
                Case EventMethods.ObjectMenu_LoadingDockCargoTypeChange
                    ObjectMenu_LoadingDockCargoTypeChange()
                Case EventMethods.ObjectMenu_ShipmentTransferToLoadingDock
                    ObjectMenu_ShipmentTransferToLoadingDock()
                Case EventMethods.ObjectMenu_ShipmentDelete
                    ObjectMenu_ShipmentDelete()
                Case EventMethods.ObjectMenu_OrderHeaderDelete
                    ObjectMenu_OrderHeaderDelete()
                Case EventMethods.ObjectMenu_OrderDetailCargoTypeChange
                    ObjectMenu_OrderDetailCargoTypeChange()
                Case EventMethods.ObjectMenu_OrderDetailDelete
                    ObjectMenu_OrderDetailDelete()
                Case EventMethods.ObjectMenu_LoadingDockExceptionRemoveLoadingDock
                    ObjectMenu_LoadingDockExceptionRemoveLoadingDock()
                Case EventMethods.ObjectMenu_LoadingDockExceptionAddLoadingDock
                    ObjectMenu_LoadingDockExceptionAddLoadingDock()
                Case EventMethods.ObjectMenu_RecurrenceLoadingDockExceptionRemoveLoadingDock
                    ObjectMenu_RecurrenceLoadingDockExceptionRemoveLoadingDock()
                Case EventMethods.ObjectMenu_RecurrenceLoadingDockExceptionAddLoadingDock
                    ObjectMenu_RecurrenceLoadingDockExceptionAddLoadingDock()
                Case EventMethods.DbiDayView1_BeforeAppointmentChange
                    DbiDayView1_BeforeAppointmentChange()
                Case EventMethods.DbiDayView1_AfterAppointmentAdd
                    DbiDayView1_AfterAppointmentAdd()
            End Select


        End Sub

        ''' <summary>Starts the business rules process and calls the appropriate "Event Method"</summary>
        ''' <remarks>This method runs Synchronously to the calling thread.</remarks>
        Public Sub StartProcessSynch(ByVal WSFObjectToProcess As Object, _
                                     ByVal RequestAction As dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects.RequestAction, _
                                     Optional ByVal businessruleParameters As  _
                                     dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects.BusinessRuleRequestParameters = Nothing)

            ProcessRule(WSFObjectToProcess, RequestAction, l_BusinessRulesToApply, _
                        "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the change?", _
                        Me.ParentForm, businessruleParameters)

        End Sub

        ''' <summary>Supporting Method: Begins the rule processing from the StartProcess Methods.</summary>
        Private Sub ProcessRule(ByVal objToProcess As Object, ByVal RuleType As dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects.RequestAction, _
                                ByVal MainBusinessRules As dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects, _
                                ByVal Message As String, ByVal ParentForm As Windows.Forms.Form, _
                                Optional ByVal businessruleParameters As  _
                                dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects.BusinessRuleRequestParameters = Nothing)

            Me.lblViolation.Text = Message
            BRResponse = MainBusinessRules.g_businessRules.ProcessRules(objToProcess, RuleType, businessruleParameters)


            If BRResponse.Level > dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects.ResponseLevel.Passed Then
                Dim strResponses As String = ""
                'Concatenate the response strings in the answer into a string with carriage return line feeds
                For Each responseReturned As String In BRResponse.Responses
                    Dim NewNode As New Dbi.WinControl.dbiNodeItem
                    NewNode.Text = responseReturned
                    NewNode.ReadOnly = True
                    Me.dbiListBusinessRules.Items.Add(NewNode)
                Next
                Me.ShowDialog(ParentForm)

            Else    'All the business rules for the shipment passed
                Me.Allow = True
                Me.DialogResult = Windows.Forms.DialogResult.OK
            End If
        End Sub
#End Region

#Region "--Event Methods--"
        'These are the methods that call the business rules for specific controls.

#Region "**Schedule Event Methods**"

        Private Sub dbiSchedule_AfterTimeBarInsert()
            Dim curSched As dbiWSF.ControlLibrary.dbiWSFSchedule = l_CallingControl
            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs = l_EventArgs
                If curSched.BusinessRulesOnShipmentAdd Then
                    Me.ProcessRule(curEventArgs.argShipment, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Add, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the adding of the shipment?", Me.ParentForm)
                    curEventArgs.Allow = Me.Allow
                End If

                If Not curEventArgs.Allow Then
                    curEventArgs.argShipment.Remove(curEventArgs.argLoadingDock)
                    curEventArgs.argDbiSchedItem.TimeBars.Remove(curEventArgs.argDbiTimebar)
                Else
                    curSched.evntClShipmentAfterAdd(Me, curEventArgs)
                End If


            Catch ex As Exception
                Throw New Exception("Invalid Event Code - dbiSchedule_AfterTimeBarInsert", ex) '<Generic Error>
            End Try
        End Sub

        Private Sub dbiSchedule_BeforeTimeBarSize()
            Dim curSched As dbiWSF.ControlLibrary.dbiWSFSchedule = l_CallingControl
            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgsShipmentMove = l_EventArgs
                If curSched.BusinessRulesOnShipmentChange Then

                    Me.ProcessRule(curEventArgs.argShipment, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Change, _
                                   l_BusinessRulesToApply, _
                                   "Business Rule Violation(s)... " & vbCrLf & _
                                   "Do you want to override and allow the change of the shipment?", Me.ParentForm)

                    curEventArgs.Allow = Me.Allow
                End If

                If Not Me.Allow Then
                    curEventArgs.argShipment.SchedStartTime = curEventArgs.argOrigStart
                    curEventArgs.argShipment.SchedEndTime = curEventArgs.argOrigEnd
                    curEventArgs.argDbiTimebar.Start = curEventArgs.argOrigStart
                    curEventArgs.argDbiTimebar.End = curEventArgs.argOrigEnd
                Else
                    curSched.evntClShipmentAfterChanged(Me, curEventArgs)
                End If




            Catch ex As Exception
                Throw New Exception("Invalid Event Code - dbiSchedule_BeforeTimeBarSize ", ex) '<Generic Error>
            End Try


        End Sub

        Private Sub dbiSchedule_BeforeTimeBarMove()
            Dim curSched As dbiWSF.ControlLibrary.dbiWSFSchedule = l_CallingControl
            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgsShipmentMove = l_EventArgs
                If curSched.BusinessRulesOnShipmentChange Then
                    Me.ProcessRule(curEventArgs.argShipment, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Change, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the change of the shipment?", Me.ParentForm)
                    curEventArgs.Allow = Me.Allow
                End If

                If Not Me.Allow Then
                    curEventArgs.argShipment.SchedStartTime = curEventArgs.argOrigStart
                    curEventArgs.argShipment.SchedEndTime = curEventArgs.argOrigEnd
                    curEventArgs.argDbiTimebar.Start = curEventArgs.argOrigStart
                    curEventArgs.argDbiTimebar.End = curEventArgs.argOrigEnd
                    curEventArgs.argDbiSchedItemTo.TimeBars.Remove(curEventArgs.argDbiTimebar)
                    curEventArgs.argDbiSchedItem.TimeBars.Add(curEventArgs.argDbiTimebar)
                    curEventArgs.argShipment.LoadingDockID = curEventArgs.argLoadingDock.LoadingDockID
                Else
                    curSched.evntClShipmentAfterChanged(Me, curEventArgs)
                End If




            Catch ex As Exception
                Throw New Exception("Invalid Event Code - dbiSchedule_BeforeTimeBarMove ", ex) '<Generic Error>
            End Try

        End Sub

        Private Sub dbiSchedule_BeforeTimeBarRemove()
            Dim curSched As dbiWSF.ControlLibrary.dbiWSFSchedule = l_CallingControl
            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFSchedule.ScheduleArgs = l_EventArgs
                If curSched.BusinessRulesOnShipmentRemove Then
                    Me.ProcessRule(curEventArgs.argShipment, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Remove, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the removal of the shipment?", Me.ParentForm)
                    curEventArgs.Allow = Me.Allow
                End If

                If curEventArgs.Allow Then
                    curEventArgs.argShipment.Remove(curEventArgs.argLoadingDock)
                    curSched.evntClShipmentAfterRemove(Me, curEventArgs)
                Else
                    Dim newTimebar As New Dbi.WinControl.Schedule.dbiTimeBarItem
                    newTimebar.Start = curEventArgs.argShipment.SchedStartTime
                    newTimebar.End = curEventArgs.argShipment.SchedEndTime
                    newTimebar.Text = curEventArgs.argShipment.Description
                    newTimebar.Tag = curEventArgs.argShipment
                    If curEventArgs.argShipment.ShipmentType = dbiWSF.FrameworkObjects.ShipmentTypes.Outbound Then
                        newTimebar.BackColorTo = System.Drawing.Color.LightGray
                    End If
                    curEventArgs.argDbiSchedItem.TimeBars.Add(newTimebar)
                End If


            Catch ex As Exception
                Throw New Exception("Invalid Event Code - dbiSchedule_BeforeTimeBarRemove", ex) '<Generic Error>
            End Try
        End Sub

#End Region

#Region "**ContextMenu Event Methods**"
        Private Sub ObjectMenu_WarehouseDelete()
            Dim curMenu As dbiWSF.ControlLibrary.dbiWSFObjectMenu = l_CallingControl
            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFObjectMenu.WSFObjectDeleteArgs = l_EventArgs

                Me.ProcessRule(curEventArgs.argsWarehouseToDelete, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Remove, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the removal of the Warehouse?", Me.ParentForm)
                curEventArgs.AllowDelete = Me.Allow

                If curEventArgs.AllowDelete Then
                    curEventArgs.argsWarehouseToDelete.Remove()
                    curMenu.TriggerUpdateDataTimer()
                End If
            Catch ex As Exception
                Throw New Exception("Invalid Event Code - ObjectMenu_WarehouseDelete", ex) '<Generic Error>
            End Try
        End Sub

        Private Sub ObjectMenu_LoadingDockTransferToWarehouse()
            Dim curMenu As dbiWSF.ControlLibrary.dbiWSFObjectMenu = l_CallingControl
            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFObjectMenu.WSFObjectTransferEventArgs = l_EventArgs

                Me.ProcessRule(curEventArgs.argsLoadingDock, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Change, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the Shipment to be transferred?", Me.ParentForm)
                curEventArgs.AllowTransfer = Me.Allow

                If curEventArgs.AllowTransfer Then
                    curMenu.TriggerUpdateDataTimer()
                Else
                    curEventArgs.argsLoadingDock.WarehouseID = curEventArgs.argsWarehouseFrom.WarehouseID
                    curMenu.TriggerUpdateDataTimer()
                End If
            Catch ex As Exception
                Throw New Exception("Invalid Event Code - ObjectMenu_LoadingDockTransferToWarehouse", ex) '<Generic Error>
            End Try
        End Sub

        Private Sub ObjectMenu_LoadingDockDelete()
            Dim curMenu As dbiWSF.ControlLibrary.dbiWSFObjectMenu = l_CallingControl

            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFObjectMenu.WSFObjectDeleteArgs = l_EventArgs

                Me.ProcessRule(curEventArgs.argsLoadingDockToDelete, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Remove, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the Loading Dock to be Deleted?", Me.ParentForm)
                curEventArgs.AllowDelete = Me.Allow

                If curEventArgs.AllowDelete Then
                    curEventArgs.argsLoadingDockToDelete.Remove(curEventArgs.argsWSFObject.GetWarehouseFromGUID(curEventArgs.argsLoadingDockToDelete.WarehouseID))
                    curMenu.TriggerUpdateDataTimer()
                End If

            Catch ex As Exception
                Throw New Exception("Invalid Event Code - ObjectMenu_LoadingDockDelete", ex) '<Generic Error>
            End Try
        End Sub

        Private Sub ObjectMenu_LoadingDockCargoTypeChange()
            Dim curMenu As dbiWSF.ControlLibrary.dbiWSFObjectMenu = l_CallingControl

            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFObjectMenu.WSFLoadingDockCargoChangeArgs = l_EventArgs

                Me.ProcessRule(curEventArgs.argsLoadingDock, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Change, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the change of the Cargo Types on the Loading Dock?", Me.ParentForm)
                curEventArgs.AllowChange = Me.Allow

                If curEventArgs.AllowChange Then
                    curMenu.TriggerUpdateDataTimer()
                Else
                    curEventArgs.argsLoadingDock.RemoveCargoType(curEventArgs.argsCargoType.CargoID)
                End If
            Catch ex As Exception
                Throw New Exception("Invalid Event Code - ObjectMenu_LoadingDockCargoTypeChange", ex) '<Generic Error>
            End Try
        End Sub

        Private Sub ObjectMenu_ShipmentTransferToLoadingDock()
            Dim curMenu As dbiWSF.ControlLibrary.dbiWSFObjectMenu = l_CallingControl

            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFObjectMenu.WSFObjectTransferEventArgs = l_EventArgs

                Me.ProcessRule(curEventArgs.argsShipment, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Change, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the shipment to be transferred?", Me.ParentForm)
                curEventArgs.AllowTransfer = Me.Allow

                If curEventArgs.AllowTransfer Then
                    curMenu.TriggerUpdateDataTimer()
                Else
                    curEventArgs.argsShipment.LoadingDockID = curEventArgs.argsLoadingDockFrom.LoadingDockID
                End If
            Catch ex As Exception
                Throw New Exception("Invalid Event Code - ObjectMenu_ShipmentTransferToLoadingDock", ex) '<Generic Error>
            End Try
        End Sub

        Private Sub ObjectMenu_ShipmentDelete()
            Dim curMenu As dbiWSF.ControlLibrary.dbiWSFObjectMenu = l_CallingControl

            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFObjectMenu.WSFObjectDeleteArgs = l_EventArgs

                Me.ProcessRule(curEventArgs.argsShipmentToDelete, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Remove, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the Shipment to be Deleted?", Me.ParentForm)
                curEventArgs.AllowDelete = Me.Allow

                If curEventArgs.AllowDelete Then
                    curEventArgs.argsShipmentToDelete.Remove(curEventArgs.argsWSFObject.GetLoadingDockFromGUID(curEventArgs.argsShipmentToDelete.LoadingDockID))
                    curMenu.TriggerUpdateDataTimer()
                End If
            Catch ex As Exception
                Throw New Exception("Invalid Event Code - ObjectMenu_ShipmentDelete", ex) '<Generic Error>
            End Try
        End Sub

        Private Sub ObjectMenu_OrderHeaderDelete()
            Dim curMenu As dbiWSF.ControlLibrary.dbiWSFObjectMenu = l_CallingControl

            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFObjectMenu.WSFObjectDeleteArgs = l_EventArgs

                Me.ProcessRule(curEventArgs.argsOrderHeaderToDelete, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Remove, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the Order to be Deleted?", Me.ParentForm)
                curEventArgs.AllowDelete = Me.Allow

                If curEventArgs.AllowDelete Then
                    curEventArgs.argsOrderHeaderToDelete.Remove(curEventArgs.argsWSFObject.GetShipmentFromGUID(curEventArgs.argsOrderHeaderToDelete.ShipmentID))
                    curMenu.TriggerUpdateDataTimer()
                End If
            Catch ex As Exception
                Throw New Exception("Invalid Event Code - ObjectMenu_OrderHeaderDelete", ex) '<Generic Error>
            End Try
        End Sub

        Private Sub ObjectMenu_OrderDetailCargoTypeChange()
            Dim curMenu As dbiWSF.ControlLibrary.dbiWSFObjectMenu = l_CallingControl

            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFObjectMenu.WSFOrderDetailCargoChangeArgs = l_EventArgs

                Me.ProcessRule(curEventArgs.argsOrderDetail, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Change, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the cargo type change on the Order Detail?", Me.ParentForm)
                curEventArgs.AllowChange = Me.Allow

                If curEventArgs.AllowChange Then
                    curMenu.TriggerUpdateDataTimer()
                Else
                    curEventArgs.argsOrderDetail.CargoTypeID = curEventArgs.argsOldCargoType.CargoID
                End If
            Catch ex As Exception
                Throw New Exception("Invalid Event Code - ObjectMenu_OrderDetailCargoTypeChange", ex) '<Generic Error>
            End Try
        End Sub

        Private Sub ObjectMenu_OrderDetailDelete()
            Dim curMenu As dbiWSF.ControlLibrary.dbiWSFObjectMenu = l_CallingControl

            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFObjectMenu.WSFObjectDeleteArgs = l_EventArgs

                Me.ProcessRule(curEventArgs.argsOrderDetailToDelete, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Remove, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the Order Detail to be Deleted?", Me.ParentForm)
                curEventArgs.AllowDelete = Me.Allow

                If curEventArgs.AllowDelete Then
                    curEventArgs.argsOrderDetailToDelete.Remove(curEventArgs.argsWSFObject.GetOrderHeaderFromGUID(curEventArgs.argsOrderDetailToDelete.OrderID))
                    curMenu.TriggerUpdateDataTimer()
                End If
            Catch ex As Exception
                Throw New Exception("Invalid Event Code - ObjectMenu_OrderDetailDelete", ex) '<Generic Error>
            End Try
        End Sub

        Private Sub ObjectMenu_LoadingDockExceptionRemoveLoadingDock()
            Dim curMenu As dbiWSF.ControlLibrary.dbiWSFObjectMenu = l_CallingControl

            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFObjectMenu.WSFObjectRemoveArgs = l_EventArgs

                Me.ProcessRule(curEventArgs.argsLoadingDockExceptionToRemoveFrom, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Remove, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the Loading Dock to be removed from the Exception?", Me.ParentForm)
                curEventArgs.AllowRemove = Me.Allow

                If curEventArgs.AllowRemove Then
                    curMenu.TriggerUpdateDataTimer()
                Else
                    curEventArgs.argsLoadingDockExceptionToRemoveFrom.AddLoadingDock(curEventArgs.argsLoadingDockToRemove.LoadingDockID)
                End If
            Catch ex As Exception
                Throw New Exception("Invalid Event Code - ObjectMenu_LoadingDockExceptionRemoveLoadingDock", ex) '<Generic Error>
            End Try
        End Sub

        Private Sub ObjectMenu_LoadingDockExceptionAddLoadingDock()
            Dim curMenu As dbiWSF.ControlLibrary.dbiWSFObjectMenu = l_CallingControl

            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFObjectMenu.WSFObjectAddArgs = l_EventArgs
                Dim params As New dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects.BusinessRuleRequestParameters
                params.collParams.Add("AddedDock", curEventArgs.argsLoadingDock)
                Me.ProcessRule(curEventArgs.argsLoadingDockException, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Add, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the Loading Dock to be add to the Exception?", Me.ParentForm, params)
                curEventArgs.AllowAdd = Me.Allow

                If curEventArgs.AllowAdd Then
                    curMenu.TriggerUpdateDataTimer()
                Else
                    curEventArgs.argsLoadingDockException.RemoveLoadingDock(curEventArgs.argsLoadingDock.LoadingDockID)
                End If
            Catch ex As Exception
                Throw New Exception("Invalid Event Code - ObjectMenu_LoadingDockExceptionAddLoadingDock", ex) '<Generic Error>
            End Try
        End Sub

        Private Sub ObjectMenu_RecurrenceLoadingDockExceptionRemoveLoadingDock()
            Dim curMenu As dbiWSF.ControlLibrary.dbiWSFObjectMenu = l_CallingControl

            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFObjectMenu.WSFObjectRemoveArgs = l_EventArgs

                Me.ProcessRule(curEventArgs.argsRecurrenceLoadingDockExceptionToRemoveFrom, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Remove, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the Loading Dock to be removed from the recurring Exception?", Me.ParentForm)
                curEventArgs.AllowRemove = Me.Allow

                If curEventArgs.AllowRemove Then
                    curMenu.TriggerUpdateDataTimer()
                Else
                    curEventArgs.argsRecurrenceLoadingDockExceptionToRemoveFrom.AddRecurrenceObject(curEventArgs.argsLoadingDockToRemove.LoadingDockID)
                End If
            Catch ex As Exception
                Throw New Exception("Invalid Event Code - ObjectMenu_RecurrenceLoadingDockExceptionRemoveLoadingDock", ex) '<Generic Error>
            End Try
        End Sub

        Private Sub ObjectMenu_RecurrenceLoadingDockExceptionAddLoadingDock()
            Dim curMenu As dbiWSF.ControlLibrary.dbiWSFObjectMenu = l_CallingControl

            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFObjectMenu.WSFObjectAddArgs = l_EventArgs
                Dim params As New dbiWSF.BusinessRulesAndSupport.BusinessRuleObjects.BusinessRuleRequestParameters
                params.collParams.Add("AddedDock", curEventArgs.argsLoadingDock)
                Me.ProcessRule(curEventArgs.argsRecurrence, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Add, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the Loading Dock to be added to the recurring Exception?", Me.ParentForm, params)
                curEventArgs.AllowAdd = Me.Allow

                If curEventArgs.AllowAdd Then
                    curMenu.TriggerUpdateDataTimer()
                Else
                    curEventArgs.argsRecurrence.RemoveObject(curEventArgs.argsLoadingDock.LoadingDockID)
                End If
            Catch ex As Exception
                Throw New Exception("Invalid Event Code - ObjectMenu_RecurrenceLoadingDockExceptionAddLoadingDock", ex) '<Generic Error>
            End Try
        End Sub


#End Region

#Region "**DayView Event Methods**"
        Private Sub DbiDayView1_BeforeAppointmentChange()
            Dim curDayView As dbiWSF.ControlLibrary.dbiWSFDayView = l_CallingControl

            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFDayView.DayViewArgsShipmentChange = l_EventArgs


                Me.ProcessRule(curEventArgs.argShipment, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Change, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the changes to the shipment?", Me.ParentForm)
                curEventArgs.Allow = Me.Allow

                If Not curEventArgs.Allow Then
                    curEventArgs.argShipment.SchedStartTime = curEventArgs.argsOldTimeStart
                    curEventArgs.argShipment.SchedEndTime = curEventArgs.argsOldTimeEnd
                    curEventArgs.argDbiAppointment.Start = curEventArgs.argsOldTimeStart
                    curEventArgs.argDbiAppointment.End = curEventArgs.argsOldTimeEnd

                    If curEventArgs.argIsShipmentLoadingDockTransfer Then
                        curEventArgs.argDbiAppointment.LocationID = curEventArgs.argLoadingDock.LoadingDockID.ToString
                        curEventArgs.argShipment.LoadingDockID = curEventArgs.argLoadingDock.LoadingDockID
                    End If
                Else
                    curDayView.evntClShipmentAfterChanged(Me, curEventArgs)

                End If


            Catch ex As Exception
                Throw New Exception("Invalid Event Code - DbiDayView1_BeforeAppointmentChange ", ex) '<Generic Error>
            End Try
        End Sub

        Private Sub DbiDayView1_AfterAppointmentAdd()
            Dim curDayView As dbiWSF.ControlLibrary.dbiWSFDayView = l_CallingControl

            Try
                Dim curEventArgs As dbiWSF.ControlLibrary.dbiWSFDayView.DayViewArgs = l_EventArgs

                Me.ProcessRule(curEventArgs.argShipment, BusinessRulesAndSupport.BusinessRuleObjects.RequestAction.Add, l_BusinessRulesToApply, "Business Rule Violation(s)... " & vbCrLf & "Do you want to override and allow the creation of the shipment?", Me.ParentForm)
                curEventArgs.Allow = Me.Allow

                If Not curEventArgs.Allow Then
                    curEventArgs.argShipment.Remove(curEventArgs.argLoadingDock)
                    curDayView.DbiDayView1.Appointments.Remove(curEventArgs.argDbiAppointment)
                Else
                    curDayView.evntClShipmentAfterAdd(Me, curEventArgs)
                End If



            Catch ex As Exception
                Throw New Exception("Invalid Event Code - DbiDayView1_AfterAppointmentAdd", ex) '<Generic Error>
            End Try
        End Sub
#End Region
#End Region

#Region "**Dialog Controls Event Methods**"
        Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
            Me.Allow = True
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            Me.Close()
        End Sub

        Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
            Me.Allow = False
            Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
            Me.Close()
        End Sub
#End Region

    End Class
End Namespace